import 'package:flutter/material.dart';

import '../utils/tools.dart';
import '../models/product_model.dart';

class ProductWidget extends StatelessWidget {
  final ProductModel item;

  final int cols;

  const ProductWidget(this.item, {Key? key, this.cols = 3}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Navigator.pushNamed(
          context,
          '/product/detail',
          arguments: {"id": item.id},
        );
      },
      child: Card(
        child: Column(
          children: [
            Center(
              child: Hero(
                tag: "product_${item.id}",
                child: item.image.isEmpty
                    ? Image.asset('assets/graphics/blank.png')
                    : FadeInImage.assetNetwork(
                        placeholder: 'assets/graphics/blank.png',
                        fadeInDuration: const Duration(seconds: 2),
                        image: Tools.fixImageUrl(item.image),
                        fit: BoxFit.cover,
                      ),
              ),
            ),
            Center(
              child: Text(
                item.title,
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.bold,
                  decoration: TextDecoration.none,
                ),
                maxLines: 2,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
